from kombu import Queue, Exchange
from datetime import timedelta
BROKER_URL = 'amqp://admin:admin123@192.168.184.145:5672'
CELERY_RESULT_BACKEND = 'redis://localhost:6379/2'

# 导入任务
CELERY_IMPORTS = (
    'day06.apps.tasks',
)


# 配置队列及交换机

# TODO 交换器：topic
"""
task1 执行task1任务
task2 执行task1、task2任务
task3 执行task3任务
"""
CELERY_QUEUES = (
    Queue('task1', Exchange('task', type='topic'), routing_key='*.task.*'),
    Queue('task2', Exchange('task', type='topic'), routing_key='*.*.task'),
    Queue('task3', Exchange('task', type='topic'), routing_key='task3'),
    Queue('task4', Exchange('task', type='topic'), routing_key='task4'),
)

CELERY_ROUTES = {
    'day06.apps.tasks.task1': {'queue': 'task1', 'routing_key': 'a.task.task'},
    'day06.apps.tasks.task2': {'queue': 'task2', 'routing_key': 'b.c.task'},
    'day06.apps.tasks.task3': {'queue': 'task3', 'routing_key': 'task3'},
    'day06.apps.tasks.task4': {'queue': 'task4', 'routing_key': 'task4'},
}


# TODO 定时任务
CELERYBEAT_SCHEDULE = {
    'task4': {
        'task': 'day06.apps.tasks.task4',
        'schedule': timedelta(seconds=10),  # TODO 间隔10秒执行一次任务
        'args': (666, 2),
        'options': {
            'queue': 'task4',
            'routing_key': 'task4'
        }
    }
}
